﻿Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.drawing

Public Class SMSMessage
    Inherits SystemClass

    Private strToPhone As String
    Private strToName As String
    Private strBody As String
    Private strFromPhone As String
    Private strFromName As String
    Private iType As Integer
    Private iStatus As Integer
    Private dteDate As Date
    Private bRead As Boolean = False
    Private bReceipt As Boolean = False

    Property ToPhone As String
        Get
            Return strToPhone
        End Get
        Set(value As String)
            strToPhone = value
            MyBase.OnPropertyChanged(Me, New PropertyChangedEventArgs("ToPhone"))
        End Set
    End Property

    Property ToName As String
        Get
            Return strToName
        End Get
        Set(value As String)
            strToName = value
            MyBase.OnPropertyChanged(Me, New PropertyChangedEventArgs("ToName"))
        End Set
    End Property

    Property Body As String
        Get
            Return strBody
        End Get
        Set(value As String)
            strBody = value
            MyBase.OnPropertyChanged(Me, New PropertyChangedEventArgs("Body"))
        End Set
    End Property

    Property FromPhone As String
        Get
            Return strFromPhone
        End Get
        Set(value As String)
            strFromPhone = value
            MyBase.OnPropertyChanged(Me, New PropertyChangedEventArgs("FromPhone"))
        End Set
    End Property

    Property FromName As String
        Get
            Return strFromName
        End Get
        Set(value As String)
            strFromName = value
            MyBase.OnPropertyChanged(Me, New PropertyChangedEventArgs("FromName"))
        End Set
    End Property

    Property Type As Integer        '0,1  (Need to check these, assume to do with incoming and outgoing
        Get
            Return iType
        End Get
        Set(value As Integer)
            iType = value
            MyBase.OnPropertyChanged(Me, New PropertyChangedEventArgs("Type"))
        End Set
    End Property

    Property Status As Integer      '3
        Get
            Return iStatus
        End Get
        Set(value As Integer)
            iStatus = value
            MyBase.OnPropertyChanged(Me, New PropertyChangedEventArgs("Status"))
        End Set
    End Property

    Property DateTime As Date
        Get
            Return dteDate
        End Get
        Set(value As Date)
            dteDate = value
            MyBase.OnPropertyChanged(Me, New PropertyChangedEventArgs("DateTime"))
        End Set
    End Property

    Property Read As Boolean
        Get
            Return bRead
        End Get
        Set(value As Boolean)
            bRead = value
            MyBase.OnPropertyChanged(Me, New PropertyChangedEventArgs("Read"))
        End Set
    End Property

    Property Receipt As Boolean
        Get
            Return bReceipt
        End Get
        Set(value As Boolean)
            bReceipt = value
            MyBase.OnPropertyChanged(Me, New PropertyChangedEventArgs("Receipt"))
        End Set
    End Property

    Public ReadOnly Property Style As DataGridViewCellStyle
        Get
            Dim ds As New DataGridViewCellStyle
            Dim fnt As Font

            If Me.Type = 0 And Me.Read = False Then
                'Unread incoming message
                fnt = New Font("Calibri", 11, FontStyle.Bold)
            ElseIf Me.Type = 1 And Me.Receipt = False Then
                'Outgoing with no receipt
                fnt = New Font("Calibri", 11, FontStyle.Italic)
            ElseIf Me.Type = 1 And Me.Receipt = True Then
                fnt = New Font("Calibri", 11, FontStyle.Regular)
            Else
                'Default style, read and receipt
                fnt = New Font("Calibri", 11, FontStyle.Regular)
            End If

            If Me.FromName = "NULL_VALUE" Then
                ds.BackColor = Color.Beige
            End If

            ds.Font = fnt
            Return ds

        End Get

    End Property

    Public ReadOnly Property Font As Font
        Get

            Dim fnt As Font

            'If Me.Type = 0 And Me.Read = False Then
            If Me.Read = False Then
                'Unread incoming message
                fnt = New Font("Calibri", 10, FontStyle.Bold)
            ElseIf Me.Type = 1 And Me.Receipt = False Then
                'Outgoing with no receipt
                fnt = New Font("Calibri", 10, FontStyle.Italic)
            ElseIf Me.Type = 1 And Me.Receipt = True Then
                fnt = New Font("Calibri", 10, FontStyle.Regular)
            Else
                'Default style, read and receipt
                fnt = New Font("Calibri", 10, FontStyle.Regular)
            End If

            Return fnt

        End Get

    End Property

    Public ReadOnly Property GridValue() As DataGridViewTextBoxCell
        Get

            Dim dc As New DataGridViewTextBoxCell
            dc.Value = DisplayText
            dc.Style = Style
            Return dc

        End Get
    End Property



    Public ReadOnly Property DisplayText As String
        Get

            If Me.Type = 0 And Me.Read = False Then
                'Unread incoming message
                Return Me.FromName & ": " & Me.Body & vbCrLf & "Received: " & Me.DateTime
            ElseIf Me.Type = 1 And Me.Receipt = False Then
                'Outgoing with no receipt
                Return "Me: " & Me.Body & vbCrLf & "Sending..."
            ElseIf Me.Type = 1 And Me.Receipt = True Then
                'Outgoing with receipt
                Return "Me: " & Me.Body & vbCrLf & "Sent: " & Me.DateTime
            Else
                'Default style, read and receipt
                Return Me.FromName & ": " & Me.Body & vbCrLf & "Received: " & Me.DateTime
            End If

        End Get
    End Property



    'Type 0 seems to be incoming (with status 0)
    'Type 1 seems to be outgoing (with status 3)

    'Public Event MessageRead(Message As SMSMessage)
    'Public Event MessageReceipt(Message As SMSMessage)



End Class
